package cn.fbs.controller;

import cn.fbs.model.TAtlasInfo;
import cn.fbs.model.TAtlasinfoTree;
import cn.fbs.service.TAtlasTypeInfoService;
import cn.fbs.vo.TAtlasVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author yuyuesheng
 * @version 1.0
 * @description:
 * @date 2021/2/1 10:37
 */
@Api(tags = "图册类型树形结构模块")
@RestController
@RequestMapping("tAtlasTypeInfo")
public class TAtlasInfoController {

    @Autowired
    private TAtlasTypeInfoService tAtlasTypeInfoService;

    @ApiOperation("查询所有的类型与图册")
    @GetMapping("/findAll")
    public List<TAtlasinfoTree> findAll() {
        return tAtlasTypeInfoService.findAll();
    }

    @ApiOperation("查询所有的类型-按照树形结构返回")
    @GetMapping("/findAllByTree")
    public List<TAtlasinfoTree> findAllByTree() {
        return tAtlasTypeInfoService.findAllByTree();
    }

//    @ApiOperation("查询所有的类型-按照树形结构返回----222")
    @GetMapping("/findAllByTree2")
    public List<TAtlasinfoTree> findAllByTree2() {
        return tAtlasTypeInfoService.findAllByTree2();
    }

    @ApiOperation("获取图册类型下所有的图册")
    @PostMapping("/getCurrentPhotoAlbum")
    public ResponseEntity getCurrentPhotoAlbum(@RequestBody TAtlasVo vo){
        List<Integer> Ids = vo.getIds();
        Integer dataType = vo.getDataType();
        String name = vo.getName();
        //分页插件
        PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
        List<TAtlasInfo> list = tAtlasTypeInfoService.getCurrentPhotoAlbum(Ids,dataType,name);
        PageInfo<TAtlasInfo> pageInfo = new PageInfo<>(list);

        return ResponseEntity.ok(pageInfo);
    }

    /**
     * 新增类型
     */
    @ApiOperation("新增图册类型")
    @PostMapping("/saveType")
    public String saveType(@RequestBody TAtlasInfo info) {
        String infos = tAtlasTypeInfoService.saveType(info);
        return infos;
    }


    /**
     * 修改类型
     */
    @ApiOperation("修改图册类型")
    @PostMapping("/updateType")
    public String updateType(@RequestBody TAtlasInfo info) {
        String message = tAtlasTypeInfoService.updateType(info);
        return message;
    }


    /**
     * 删除类型
     */
    @ApiOperation("删除图册类型")
    @GetMapping("/deleteType")
    @ApiImplicitParam(name = "id", value = "类型ID", required = true)
    public ResponseEntity<Map<String, Object>> deletePhotoAlbum(@RequestParam("id") String id) {
        return ResponseEntity.ok(tAtlasTypeInfoService.deleteType(id));
    }


}
